package 用两个栈实现队列;

import java.util.LinkedList;

/**
 * 问题:
 * 1. 容器及容器API
 * 2. 栈, 队列 数据结构
 */
public class CQueueV2 {

    LinkedList<Integer> stackA;
    LinkedList<Integer> stackB;

    public CQueueV2() {
        stackA = new LinkedList<>();
        stackB = new LinkedList<>();
    }

    public void appendTail(int value) {
        stackA.push(value);
    }

    public int deleteHead() {
        if(stackB.isEmpty()) {
            while(!stackA.isEmpty()) {
                stackB.push(stackA.pop());
            }
        }
        if (stackB.isEmpty()) {
            return -1;
        } else {
            return stackB.pop();
        }
    }
}
